package org.example.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LoggingAspect {
    // 在执行UserService的每个方法前执行
    @Before("execution(public * org.example.service.UserService.*(..))")
    public void doAccessBefore() {
        System.err.println("[before]:do access check...");
    }

    // 在执行MailService的每个方法前后执行
    @Around("execution(public * org.example.service.MailService.*(..))")
    public Object doAccessAround(ProceedingJoinPoint joinPoint) throws Throwable {
        System.err.println("[around]:start " + joinPoint.getSignature());
        Object retVal = joinPoint.proceed();
        System.err.println("[around]:after " + joinPoint.getSignature());
        return retVal;
    }
}
